package com.zsk.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zsk.shop.entity.ShopUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ShopUserMapper extends BaseMapper<ShopUser> {

    /**
     * 获取用户总数
     * @author Ys
     * @date 2022/2/10 9:49
     * @return int
     */
    @Select("SELECT invite_code FROM shop_user ORDER BY id DESC LIMIT 1")
    Long getUserCount();


    /**
     * 获取用户上级手机号
     * @param phone
     * @return
     */
    @Select("SELECT phone FROM shop_user WHERE user_no=(SELECT parent_user_no FROM shop_user WHERE phone=#{phone} LIMIT 1) LIMIT 1")
    String getParentUserPhoneList(@Param("phone") String phone);

    /**
     * 获取用户的下级
     * @param phone
     * @return
     */
    @Select("SELECT phone FROM shop_user WHERE parent_user_no=(SELECT user_no FROM shop_user WHERE phone=#{phone} LIMIT 1)")
    List<String> getUserPhoneList(@Param("phone") String phone);
}